package com.secondary.action.adminAction;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.secondary.action.BaseAction;
import com.secondary.pojos.Administrator;
import com.secondary.pojos.Goods;
import com.secondary.pojos.User;
import com.secondary.service.AdminService;
import com.secondary.service.GoodsService;
@ParentPackage(value = "struts-default")
@Namespace(value = "/adminLogin")
@Action(value="adminLogin")
@Results({ 
	@Result(name = "logSuccess", location = "/admin/admin!showUncheckedGoods.action" ,type = "redirect"),
	@Result(name="logFail",location="/admin/adminLogin.jsp"),
		})
public class AdminLoginAction extends BaseAction{
	@Resource
	private AdminService adminService;
	@Resource
	private GoodsService goodsService;
	private List<Goods> uncheckedGoods;
	private List<User> userList;
	private Goods good;
	public String  login(){
		String username=super.getRequestParameter("username");
		String pwd =super.getRequestParameter("pwd");
		Administrator lgAdmin=adminService.login(username, pwd);
		if(lgAdmin!=null){
			
			super.setSessionAttribute("admin", lgAdmin);
			System.out.println("success");
			return "logSuccess";
		}else{
			System.out.println("fail");
			return "logFail";
		}
	}
	
	
	public AdminService getAdminService() {
		return adminService;
	}
	public void setAdminService(AdminService adminService) {
		this.adminService = adminService;
	}
	public List<Goods> getUncheckedGoods() {
		return uncheckedGoods;
	}
	public void setUncheckedGoods(List<Goods> uncheckedGoods) {
		this.uncheckedGoods = uncheckedGoods;
	}
	public List<User> getUserList() {
		return userList;
	}
	public void setUserList(List<User> userList) {
		this.userList = userList;
	}
	public GoodsService getGoodsService() {
		return goodsService;
	}
	public void setGoodsService(GoodsService goodsService) {
		this.goodsService = goodsService;
	}
	public Goods getGood() {
		return good;
	}
	public void setGood(Goods good) {
		this.good = good;
	}
	
		
	
}
